import pandas as pd

# with open('2021-05-17-09_26_59to2021-06-21-09_26_59.csv') as f:
B = 1
D = 1
waveLength = 635 * (10**(-9))
#横向系数
Kt = 0.364*(1-0.7982*(B**(-1/3))-0.018*(B**(-7/3)))
#纵向系数
Kl = 0.364*(1-0.532*(B**(-1/3))-0.024*(B**(-7/3)))

csvfile = pd.read_csv('2021-05-17-09_26_59to2021-06-21-09_26_59.csv', sep=',', chunksize=1000)
def R0Transverse():
    for csvfile1 in csvfile:
        x = csvfile1.iloc[:,1:5:2].diff(axis=0)        # x是对横向数据进行差分计算
        variance2 = (x.iloc[:,0] - x.iloc[:,1])**2   # 计算差分的平方，这里是横向的方差
        r0 = (Kt * (waveLength**2) *(D**(-1/3))/variance2)**(-5/3)    #计算出视宁度
        print(len(x), x)
        print(variance2)

#纵向，同上
def RoLongitudinal():
    for csvfile1 in csvfile:
        x = csvfile1.iloc[:,2:5:2].diff(axis=0)
        variance2 = (x.iloc[:,0] - x.iloc[:,1])**2
        r0 = (Kl * (waveLength**2) *(D**(-1/3))/variance2)**(-5/3)
        print(len(x),x)
        print('*',r0)

# R0Transverse()
RoLongitudinal()





# csvfile.rename(index={'时间':'times'})
# print(csvfile.diff(axis=0))
# print(pd.DataFrame.diff(csvfile, axis=0))
# for i in csvfile:
#     print(i.iloc[:, 1:5])
#     print(pd.DataFrame.diff(i, axis=0))


# print(csvfile.dtypes)
